package com.example.sinoyd.frameapplication.KotlinFrame.Uitl

import android.app.Activity
import android.app.Fragment
import android.content.Context
import android.graphics.Color
import com.xiasuhuei321.loadingdialog.view.LoadingDialog

/**
 * allprojects {
 *               repositories {
 *                                ...
 *                              maven { url "https://jitpack.io" }
 *                            }
 *              }
 *
 * dependencies {
 *               compile 'com.github.ForgetAll:LoadingDialog:v1.0.4'
 *              }
 *
 */

var ld: LoadingDialog? = null

//发送请求dialog提示  Activity
fun Fragment.showdialog(con: Context, str: String): Unit {
    if (ld == null) {
        ld = LoadingDialog(con)
        ld!!.setLoadingText("加载中")
                .setSuccessText("加载成功")
                .setFailedText("加载失败")
                .setInterceptBack(false)
                .setLoadSpeed(LoadingDialog.Speed.SPEED_ONE)
                .setRepeatCount(1)
                .setDrawColor(Color.WHITE)
    }
    when (str) {
        "loadshow" -> ld!!.show()
        "loadsuccess" -> {
            ld!!.loadSuccess()
            ld!!.close()
            ld = null
        }
        "loadfail" -> {
            ld!!.loadFailed()
            ld!!.close()
            ld = null
        }
        "loaddismiss" -> {
            ld!!.close()
            ld = null
        }
    }
}


//发送请求dialog提示  Activity
fun Fragment.showdialogchcek(con: Context, str: String): Unit {
    if (ld == null) {
        ld = LoadingDialog(con)
        ld!!.setLoadingText("正在检查")
                .setSuccessText("检查成功")
                .setFailedText("检查失败")
                .setInterceptBack(false)
                .setLoadSpeed(LoadingDialog.Speed.SPEED_ONE)
                .setRepeatCount(1)
                .setDrawColor(Color.WHITE)
    }
    when (str) {
        "loadshow" -> ld!!.show()
        "loadsuccess" -> {
            ld!!.loadSuccess()
            ld!!.close()
            ld = null
        }
        "loadfail" -> {
            ld!!.loadFailed()
            ld!!.close()
            ld = null
        }
        "loaddismiss" -> {
            ld!!.close()
            ld = null
        }
    }
}

//发送请求dialog提示  Activity
fun showdialog(con: Context, dow: String, str: String, interfacename: String): Unit {
    if (ld == null) {
        ld = LoadingDialog(con)
        ld!!.setLoadingText("下载${interfacename}中...")
                .setSuccessText("下载${interfacename}成功")
                .setFailedText("下载${interfacename}失败")
                .setInterceptBack(false)
                .setLoadSpeed(LoadingDialog.Speed.SPEED_ONE)
                .setRepeatCount(1)
                .setDrawColor(Color.WHITE)
    }
    when (str) {
        "loadshow" -> ld!!.setLoadingText("下载${interfacename}").show()
        "loadsuccess" -> {
            ld!!.loadSuccess()
            ld!!.close()
            ld = null
        }
        "loadfail" -> {
            ld!!.loadFailed()
            ld!!.close()
            ld = null
        }
        "loaddismiss" -> {
            ld!!.close()
            ld = null
        }
    }
}